package com.example.springmvc250513.controller;

import com.example.springmvc250513.model.User;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/param")
@RestController
public class ParamController {
    @RequestMapping("/p1")
    public String p1(String name){
        return "接收到参数，name:" + name;
    }

    @RequestMapping("/p2")
    public String p2(Integer age){
        return "接受到参数,age:" + age;
    }

    @RequestMapping("/p3")
    public String p3(int age){
        return "接受到参数,age:" + age;
    }

    @RequestMapping("/p4")
    public String p4(String name,Integer age){
        return "接受到参数,age:" + age + ",name:" + name;
    }

    @RequestMapping("/p5")
    public String p5(String name,Integer age,String gender){
        return "接受到参数,age:" + age + ",name:" + name + ",gender:" + gender;
    }

    @RequestMapping("/p6")
    public String p6(User user){
        return "user:" + user;
    }

    @RequestMapping("/p7")
    public String p7(@RequestParam("userName") String name){
        return "接收到参数，name:" + name;
    }

    @RequestMapping("/p8")
    public String p8(@RequestParam(value = "userName",required = false) String name){
        return "接收到参数，name:" + name;
    }

    @RequestMapping("/p9")
    public String p9(String[] arr){
        return "arr:" + List.of(arr);
    }

    @RequestMapping("/p10")
    public String p10(@RequestParam List<String> list){
        return "list:" + list;
    }

    @RequestMapping("/p11")
    public String p11(@RequestBody User user){
        return "user:" + user;
    }

    //获取URL中的参数
    @RequestMapping("/article/{articleId}")
    public String p12(@PathVariable String articleId){
        return "articleId:" + articleId;
    }

    @RequestMapping("/article/{articleId}/{name}")
    public String p13(@PathVariable String articleId,@PathVariable String name){
        return "articleId:" + articleId + ",name:" + name;
    }

//    //接收文件
//    @RequestMapping("/p14")
//    public String p14(@RequestPart("fileName") MultiPartFile file){
//        System.out.println();
//        return "文件名称：" ;
//    }

}
